/* @(#)GSOperatorManageQueryAction.java   
 *
 * Project: GS
 *
 * Modify Information:
 * =============================================================================
 *   Author       Date       Description
 *   ------------ ---------- ---------------------------------------------------
 *   Jenny Li    2006-3-9     新增
 *
 * Copyright Notice:
 * =============================================================================
 *    Copyright (c) 2001-2006 Beijing HiTRUST Technology Co., Ltd. 1808 Room, 
 *        Science & Technology Building, No. 9 South Street, Zhong Guan Cun, 
 *        Haidian District, Beijing ,100081, China All rights reserved.
 *
 *    This software is the confidential and proprietary information of
 *        Beijing HiTRUST Technology Co., Ltd. ("Confidential Information").
 *        You shall not disclose such Confidential Information and shall use it
 *        only in accordance with the terms of the license agreement you entered
 *        into with HiTRUST.
 *
 * Warning:
 * =============================================================================
 * 
 */
package com.hitrust.gs.action;

import java.util.ArrayList;
import java.util.HashMap;
import com.hitrust.gs.bean.GSOperatorBean;
import com.hitrust.gs.business.GSOperatorProcessor;
import com.hitrust.gs.form.GSOperatorScanQueryForm;
import com.hitrust.gs.lib.GSBaseConstants;
import com.hitrust.gs.service.GSBaseAction;
import com.hitrust.gs.service.GSBaseForm;
import com.hitrust.gs.util.exception.GSException;
import com.hitrust.gs.util.page.ResultProcess;

/**
 *  
 */
public class GSOperatorManageQueryAction extends GSBaseAction {

    public String execute(GSBaseForm aForm) throws Exception {
        GSOperatorScanQueryForm tForm = (GSOperatorScanQueryForm) aForm;
        //取得页面查询参数
        GSOperatorBean tGSOperatorBean = new GSOperatorBean();
        tGSOperatorBean.setGs_oper_id(tForm.getOperId());
        tGSOperatorBean.setGs_oper_name(tForm.getOperName());
        tGSOperatorBean.setGs_oper_org_id(tForm.getOperOrgId());
        tGSOperatorBean.setGs_key_word(tForm.getKeyWord());
        
        GSOperatorProcessor tGSOperatorProc = new GSOperatorProcessor();

        GSOperatorBean tGSCurOperator = (GSOperatorBean) tForm.getSession().getAttribute(GSBaseConstants.LOGIN);
        
        //取得页面查询模式
        String querymode = aForm.getRequest().getParameter("querymode");
        aForm.getRequest().setAttribute("querymode",querymode);
        
        if ("QP".equalsIgnoreCase(querymode)) {
            ResultProcess tProc = new ResultProcess();
            try{
                ArrayList arylist = tGSOperatorProc.queryOperatorWithPwd(tGSOperatorBean);
                tProc.setResult(arylist);
            } catch(GSException e) {
                aForm.getRequest().setAttribute("action", "A400501.do");
                throw e;               
            }
            tForm.getRequest().setAttribute("Operator", tProc);
            tForm.getRequest().setAttribute("curoperator", tGSCurOperator);

            //取得可查询操作员及组织之间的关系集
            HashMap tMap = GSOperatorProcessor.getViewableOrgAndOperator(tGSCurOperator);
            //取得操作员所属企业及其所有下级企业
            ArrayList tList = (ArrayList)tMap.get("organization");
            aForm.getRequest().setAttribute("Organization",tList);
            tMap.remove("organization");
            aForm.getRequest().setAttribute("OrgAndOper",tMap);
            
            return GSBaseConstants.FORWARD_SUCCESS;
        }


        //查询符合条件的操作员
        ResultProcess tProc = null;
        try {

            tProc = tGSOperatorProc.getOpersByOptForManage(tGSOperatorBean);
        } catch (GSException e) {
            aForm.getRequest().setAttribute("action", "A400501.do");
            throw e;
        }
        tForm.getRequest().setAttribute("Operator", tProc);


        //取得可查询操作员及组织之间的关系集
        GSOperatorBean tCurOper = (GSOperatorBean)aForm.getSession().getAttribute(GSBaseConstants.LOGIN);
        HashMap tMap = GSOperatorProcessor.getViewableOrgAndOperator(tCurOper);
        //取得操作员所属企业及其所有下级企业
        ArrayList tList = (ArrayList)tMap.get("organization");
        aForm.getRequest().setAttribute("Organization",tList);
        tMap.remove("organization");
        
        aForm.getRequest().setAttribute("OrgAndOper",tMap);

        return GSBaseConstants.FORWARD_SUCCESS;
    }

}